var ipcR = require('electron').ipcRenderer
var $ = require('jquery')

$('#connBtn').on('click',function(){
    var host = $('#host').val();
    var user = $('#user').val();
    var pwd = $('#pwd').val();
    var database = $('#database').val();
    var port = $('#port').val();

    var body = {
        "host" : host,
        "user" : user,
        "pwd" : pwd,
        "database" : database,
        "port" : port
    }
    
    var result = ipcR.sendSync('connTest',body);
    if(result == 'fail'){
        alert('连接失败')
    }else{
        alert('连接成功')
        $('#import').css('display','block');
    }
})


$("#uploadBtn").on('click',function(){
    var file = $("#upload")[0].files[0];
    var renBody = ipcR.sendSync('readExcel',file.path);

    // console.log(renBody);
    $('#log').empty();
    if(renBody.length == 0){
        $('#log').append('运行失败');
    }else{
        renBody.forEach(function(v,i){
            $('#log').append(`${i+1} \t\t\t ${v.sheetName}\t\t\t ${v.msg}<br/>`);
        });
    }
   
})
